package com.shopx.task;


import com.shopx.core.common.CommonConstant;
import com.shopx.core.context.ShopxContext;
import com.shopx.core.utils.IDUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

@Component("abstractQuatazJob")
@EnableScheduling
@Slf4j
public abstract class AbstractQuatazJob{
	
	public void execute() throws Exception {}
	
	public void doExecute() {
		ShopxContext ctx = null;
		try {
			//-- 创建线程上下文，生产requestId
			String trcId = IDUtils.getId32("");
			ctx = ShopxContext.createAndPushContext();
			ctx.setProperty(CommonConstant.TRACE_ID, trcId);
			MDC.put(CommonConstant.TRACE_ID, trcId);
			ctx.setProperty(CommonConstant.REQ_INITIATOR, CommonConstant.Initiator.BUILD);
			execute();
		} catch (Exception e) {
			log.error("AbstractQuatazJob excute error",e);
		} finally {
			if (ctx != null) {
				ctx.removeCurrentContext();
				ctx.clear();
			}
		}
	}
}
